#include <stdio.h>
#include "SDL2/SDL.h"



static SDL_mutex *m_mutex;
static SDL_cond *m_cond;
static int first_end = 0;
static int second_end = 0;


int first_func_print()
{
    SDL_LockMutex(m_mutex);
    for (int i = 0; i < 5; i++)
    {
        printf("first_func_print %d\n", i);
    }
    SDL_CondSignal(m_cond);
    SDL_CondWait(m_cond, m_mutex);
    for (int i = 5; i < 10; i++)
    {
        printf("first_func_print %d\n", i);
    }
    first_end = 1;
    SDL_UnlockMutex(m_mutex);
    return 1;
}

int second_func_print()
{
    SDL_LockMutex(m_mutex);
    for (int i = 0; i < 5; i++)
    {
        printf("second_func_print %d\n", i);
    }
    SDL_CondSignal(m_cond);
    second_end = 1;
    SDL_UnlockMutex(m_mutex);
    return 1;
}

int main(int argc, char *argv[])
{
    m_mutex = SDL_CreateMutex();
    m_cond = SDL_CreateCond();
    SDL_CreateThread(first_func_print, "first_func_print", NULL);
    SDL_CreateThread(second_func_print, "second_func_print", NULL);
    while(!first_end || !second_end){
        
    }
    printf("print end \n");
    SDL_DestroyCond(m_cond);
    SDL_DestroyMutex(m_mutex);
    SDL_Quit();
}